package top.healthylife.gateway.mgr.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import top.healthylife.gateway.mgr.mapper.GatewayAccountMapper;
import top.healthylife.gateway.mgr.service.GatewayAccountService;
import top.heathylife.gateway.common.po.GatewayAccountPo;

import java.util.List;

/**
 * @author maoxiaomeng
 */
@Service
public class GatewayAccountServiceImpl extends ServiceImpl<GatewayAccountMapper, GatewayAccountPo> implements GatewayAccountService {

    @Override
    public Page<GatewayAccountPo> pageQuery(String shortName, String secretName, String env, Page<GatewayAccountPo> page) {
        return page(page,buildWrapper(shortName,secretName,env));
    }

    @Override
    public List<GatewayAccountPo> listQuery(String shortName, String secretName, String env) {
        return list(buildWrapper(shortName,secretName,env));
    }

    private LambdaQueryWrapper<GatewayAccountPo> buildWrapper(String shortName, String secretName, String env){
       return Wrappers.<GatewayAccountPo>lambdaQuery()
                .eq(ObjectUtil.isNotEmpty(shortName),GatewayAccountPo::getShortName,shortName)
                .like(ObjectUtil.isNotEmpty(secretName),GatewayAccountPo::getSecretName,secretName)
                .eq(ObjectUtil.isNotEmpty(env),GatewayAccountPo::getEnv,env);
    }
}
